package com.asa.wanandroid_compose.ui.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.StrokeCap.Companion.Square
import androidx.navigation.NavController
import com.asa.wanandroid_compose.ui.ui.mine.Mine
import com.asa.wanandroid_compose.ui.ui.square.Square
import com.asa.wanandroid_compose.ui.ui.wechat.WeChat
import com.asa.wanandroid_compose.widget.BottomTab
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState
import kotlinx.coroutines.launch


@ExperimentalPagerApi
@Composable
fun Main(navController: NavController){
    Column(Modifier.fillMaxSize()) {
        val scope = rememberCoroutineScope()
        val pageState = rememberPagerState(pageCount = 4,initialOffscreenLimit = 3)
        HorizontalPager(pageState,Modifier.weight(1f)) { page->
            when(page){
                0-> Home(navController)
                1-> Square(navController)
                2-> WeChat(navController)
                3-> Mine(navController)
            }
        }
        BottomTab(pageState.currentPage){
            scope.launch {
                pageState.scrollToPage(it)
            }
        }
    }
    
}
